package main

import (
	"gin-demo/common/result"
	"gin-demo/middleware"
	"log"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {
	engine := gin.Default()
	//engine.SetTrustedProxies(nil)

	engine.Use(gin.CustomRecovery(middleware.CustomRecovery))
	//engine.Use(middleware.Authentication)
	//engine.Use(middleware.Authorization(common.InitCasbin()))
	engine.Use(middleware.RedisCache)
	engine.Use(middleware.ErrorHandler)

	engine.GET("ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, result.Success(gin.H{"message": "pong"}))
	})

	engine.GET("ping2", func(c *gin.Context) {
		c.JSON(http.StatusOK, result.Success(nil))
	})

	engine.GET("/login", InitAuthHandler().Login)

	apiGroup := engine.Group("/api")
	{
		apiGroup.GET("/getUserById", InitUserHandler().GetUserById)
	}

	err := engine.Run(":8088")
	if err != nil {
		log.Fatalln("启动失败")
	}
}
